package org.linphone.utils;

import android.content.Context;


import org.linphone.LinphoneManager;
import org.linphone.LinphoneService;

/**
 * Created by dds on 2018/7/11.
 * android_shuai@163.com
 */

public class VoipUtil {


    // 开启Voip服务
    public static void startService(Context context) {

        //开启Voip服务
        LinphoneHelper.getInstance().startLinphoneService(context);

    }

    //登录服务器
    public static void login(String domian,String userId, String password) {
        LinphoneHelper.getInstance().register(userId, password, domian);
    }

    // 拨打电话
    public static void outgoing( String callName, boolean isVideoEnable) {
        //拨打电话之前先暂停对讲
        LinphoneHelper.getInstance().pauseTalkCall(LinphoneService.talkRoom);
        LinphoneHelper.getInstance().call(  callName, isVideoEnable);
    }

    /**
     * 启动对讲
     * @param to
     */
    public static void startTalk(String to){
        System.out.println("AAAAA" + System.currentTimeMillis());
        LinphoneService.instance().talkRoom = null;
        //拨打对讲电话之前先停止所有通话
        LinphoneManager.getLcIfManagerNotDestroyedOrNull().terminateAllCalls();
        LinphoneService.instance().talkRoom = to;
        String number = to+"@192.168.1.199";
        LinphoneManager.getInstance().newOutgoingCall(number, false);
    }

    //关闭Voip服务
    public static void stopService(Context context) {
        LinphoneHelper.getInstance().unRegister();
        LinphoneHelper.getInstance().stopVoip(context);

    }

}
